<?php
$caption = BUtils::T('register_lbl');
$this->pageTitle = Yii::app()->name . ' - ' . $caption;

//make categories for merchants
$categories = MerchantObject::Categories();
$all_areas_fi = MerchantObject::BusinessAreas();
$cities_fi = array_keys($all_areas_fi);
?>
<div class="container prepend-top append-bottom">
	<div class="span-10 prepend-2">
		<!-- <div class="box_white append-bottom">
			<div class="biz-form margin">
				<h3><?php echo BUtils::T('yb_how_works_lbl'); ?></h3>
				<div class="tips"><?php echo BUtils::T('yb_how_works_eg'); ?></div>
				<ul class="line">
					<li><?php echo BUtils::T('yb_how_works_t1'); ?></li>
					<li><?php echo BUtils::T('yb_how_works_t2'); ?></li>
					<li><?php echo BUtils::T('yb_how_works_t3'); ?></li>
				</ul>
			</div>
		</div> -->
		<div class="box_white append-bottom">
			<div class="biz-form margin">
				<h3><?php echo BUtils::T('yb_why_use_lbl'); ?></h3>
				<div class="tips"><?php echo BUtils::T('yb_why_use_eg'); ?></div>
				<ul class="line">
					<li>
						<b><?php echo BUtils::T('yb_why_use_t1'); ?></b>
						<br />
						<span><?php echo BUtils::T('yb_why_use_t1_eg'); ?></span>
					</li>
					<li>
						<b><?php echo BUtils::T('yb_why_use_t2'); ?></b>
						<br />
						<span><?php echo BUtils::T('yb_why_use_t2_eg'); ?></span>
					</li>
					<li>
						<b><?php echo BUtils::T('yb_why_use_t3'); ?></b>
						<br />
						<span><?php echo BUtils::T('yb_why_use_t3_eg'); ?></span>
					</li>
				</ul>
				<div style="text-align:right;">
					<a class="button button-huge button-confirm" href="<?php echo Yii::app()->createUrl('/help/about'); ?>">
						<span><?php echo BUtils::T('learn_more_lbl'); ?></span>
					</a>
				</div>
			</div>
		</div>
		
		<div class="box_white append-bottom">
			<div class="biz-form margin" style="text-align:center;">
				<h3><?php echo BUtils::T('yb_app_merchant_msg'); ?></h3>
				<br />
				<div class="tips">
					<a href="https://itunes.apple.com/fi/app/yamii-for-business/id593346524" target="_blank"><img src="<?php echo Yii::app()->baseUrl; ?>/images/app-store-icon.png" alg="app store"></a>
					<a href="https://play.google.com/store/apps/details?id=com.yamii.business.android" target="_blank"><img src="<?php echo Yii::app()->baseUrl; ?>/images/google-play-icon.png" alg="google play"></a>
				</div>
			</div>
		</div>
	</div>
	
	<div class="span-10 prepend-1 last">
		<div class="box_white append-bottom">
		<div class="biz-form">
			<div class="margin">
				<h3><?php echo $caption; ?></h3>
			</div>
<?php
if (Yii::app()->user->hasFlash('error')) {
	echo '<div class="fieldswrap"><div class="fields">';
	echo Yii::app()->user->getFlash('error');
	echo '</div></div>';
} elseif (Yii::app()->user->hasFlash('register')) {
	echo '<div class="fieldswrap"><div class="fields">';
	echo Yii::app()->user->getFlash('register');
	echo '</div><div class="margin actions">';
	echo CHtml::link('<span>'.BUtils::T('have_account_already_lbl').'</span>', Yii::app()->user->loginUrl, array('class' => 'button button-huge button-thin button-compliment'));
	echo '</div></div>';
} else {
	$form=$this->beginWidget('CActiveForm', array(
		'id'=>'register-form',
		'enableClientValidation'=>true,
		'clientOptions'=>array(
			'validateOnSubmit'=>true,
		),
	));
?>
<div class="fieldswrap">
<div class="fields">
	<div class="block">
		<div class="lbl"><?php echo $form->labelEx($model,'name'); ?></div>
		<div class="ipt">
			<?php echo $form->textField($model,'name', array('class'=>'auto')); ?>
			<?php echo $form->error($model,'name'); ?>
		</div>
	</div>
	<div class="block">
		<div class="lbl"><?php echo $form->labelEx($model,'category_key'); ?></div>
		<div class="ipt">
			<?php echo $form->dropDownList($model, 'category_key', $categories, array('empty'=>'')); ?>
			<?php echo $form->error($model,'category_key'); ?>
		</div>
		<div class="eg"><?php echo BUtils::T('category_business_eg'); ?></div>
	</div>
	<div class="block">
		<div class="lbl"><?php echo $form->labelEx($model,'email'); ?></div>
		<div class="ipt">
			<?php echo $form->textField($model,'email', array('class'=>'auto')); ?>
			<?php echo $form->error($model,'email'); ?>
		</div>
	</div>
	<div class="block">
		<div class="lbl"><?php echo $form->labelEx($model,'phone'); ?></div>
		<div class="ipt">
			<?php echo $form->textField($model,'phone', array('class'=>'auto')); ?>
			<?php echo $form->error($model,'phone'); ?>
		</div>
	</div>
	<div class="block">
		<div class="lbl"><?php echo $form->labelEx($model,'address'); ?></div>
		<div class="ipt">
			<?php echo $form->textField($model,'address', array('class'=>'auto')); ?>
			<?php echo $form->error($model,'address'); ?>
		</div>
	</div>
	<div class="block">
		<div class="lbl"><?php echo $form->labelEx($model,'city'); ?></div>
		<div class="ipt">
			<?php echo $form->textField($model,'city'); ?>
		</div>
	</div>
<?php
echo $form->hiddenField($model,'latitude');
echo $form->hiddenField($model,'longitude');
echo $form->hiddenField($model,'postcode');
echo $form->hiddenField($model,'country_code');
?>
</div><!-- end of .fields -->
</div><!-- end of .fieldswrap -->

	<div class="margin actions">
		<?php echo CHtml::submitButton(BUtils::T('register_lbl'), array('class' => 'button button-huge button-confirm')); ?>
		<?php echo CHtml::link('<span>'.BUtils::T('have_account_already_lbl').'</span>', Yii::app()->user->loginUrl, array('class' => 'button button-huge button-thin button-compliment')); ?>
	</div>

<?php
	$this->endWidget();
}
?>

		</div><!-- end of <div class="biz-form"> -->
		</div>
	</div>
</div>
<script type="text/javascript">
$(function() {
	$("#MerchantForm_address").geocomplete({
		details: '.geo-info', location: []
	}).bind("geocode:result", function(event, result){
		setLocationValues(result);
	});
});
function setLocationValues(loc) {
	var lat = loc.geometry.location.lat();
	var lng = loc.geometry.location.lng();
	var locArray = loc.formatted_address.split(', ');
	if (locArray.length > 2) {
		//console.log(locArray);
		var street_number, address, postal_code, city, country, country_code;
		$.map(loc.address_components, function(obj) {
			switch (obj.types[0]) {
				case 'postal_code':
					postal_code = obj.long_name;
					break;
				case 'country':
					country = obj.long_name;
					country_code = obj.short_name;
					break;
				case 'locality':
				case 'administrative_area_level_3':
					if (city == null) city = obj.long_name;
					break;
				case 'administrative_area_level_1':
					if (city == null) city = obj.long_name;
					break;
				case 'route':
					address = obj.long_name;
					break;
				case 'street_number':
					street_number = obj.long_name;
					break;
			}
		});
		if (country_code != null) {
			$('#MerchantForm_latitude').val(lat);
			$('#MerchantForm_longitude').val(lng);
			$("#MerchantForm_postcode").val(postal_code);
			$("#MerchantForm_city").val(city);
			$("#MerchantForm_country_code").val(country_code);
		}
	}
}
</script>
<?php
$langcode = Yii::app()->language;
if ($langcode == 'zh_cn') $langcode = 'en';
?>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places&language=<?php echo $langcode; ?>"></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/labs/jquery.geocomplete.min.js"></script>